//
//  WarGameDecks.m
//  WarGame
//
//  Created by iD Student on 6/27/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "WarGameDecks.h"


@interface WarGameDecks()


@property(nonatomic, strong) NSMutableArray * fullDeck;
@property(nonatomic, strong) NSMutableArray * playerDeck;
@property(nonatomic, strong) NSMutableArray * botDeck;


@end

@implementation WarGameDecks
@synthesize fullDeck = _fullDeck;
-(NSMutableArray *)fullDeck
{
    if(!_fullDeck)
    {
        _fullDeck = [NSMutableArray arrayWithCapacity:52];
        for (int i =0; i<52; i++)
        {
            [_fullDeck addObject:[NSNumber numberWithInt:i]] ;
        
        }
            
    }
    return _fullDeck;
}

@synthesize playerDeck = _playerDeck;
@synthesize botDeck = _botDeck;

-(void)shuffleFullDeck
{
    //loop through the deck
    for(int i =0; i<51;  i++)
    {
        //swap the item with a random item further in the array
        [self.fullDeck exchangeObjectAtIndex:i withObjectAtIndex:arc4random_uniform(51-i)+i];
    }
    NSRange pl = NSMakeRange(0, 26);
    NSRange bo = NSMakeRange(26, 26);
    
    
    self.playerDeck = [[self.fullDeck subarrayWithRange:pl] mutableCopy];
    self.botDeck = [[self.fullDeck subarrayWithRange:bo] mutableCopy];
    
    
}


//acessor functions for the player deck
-(int)pullFromTopOfPlayerDeck
{
    int num = [[self.playerDeck objectAtIndex:0] intValue];
    [self.playerDeck removeObjectAtIndex:0];
    return num;
}
-(void)putOnBottomOfPlayerDeck:(int)cardToGoOnBottomOfDeck
{
    [self.playerDeck addObject:[NSNumber numberWithInt:cardToGoOnBottomOfDeck]];
    
}
-(int)getPlayerDeckSize
{
    int num = [self.playerDeck count];
    return num;
}

//acessor functions for bot deck
-(int)pullFromTopOfBotDeck
{
    int num = [[self.botDeck objectAtIndex:0] intValue];
    [self.botDeck removeObjectAtIndex:0];
    return num;

}
-(void)putOnBottomOfBotDeck:(int)num
{
    [self.botDeck addObject:[NSNumber numberWithInt:num]];
}
-(int)getBotDeckSize
{
    int num = [self.botDeck count];
    return num;

}


        
        
@end
